​大概在一个月前开始接触模式识别、人工神经网络、图像识别方向。

从Matlab开始一边理解神经网络层一边看代码跑了最基础的MNIST识别手写数字的代码,中间遇到了很多问题,比如说在图像处理方面CPU远不及GPU强而在IO读写上CPU又很占优势。当我在进一步学习卷积神经网络的过程中发现了Matlab的强大和不足。在两年前Google爸爸出品了TensorFlow这一深度学习开源框架。历经2天1夜13次重装系统。。。所以为什么要怒发教程,你懂的。话不多说直接开配!


requirements

  • Ubuntu-16.04
  • python-2.7
  • cuda-8
  • cuDNN-5.1
  • tensorflow GPU 版本

    安装nvidia driver

经过不断踩坑的安装,终于google到了靠谱的方法,首先检查你的NVIDIA VGA card model

Ctrl+Alt+T 打开终端 输入:

1
sudo lshw -numeric -C display

可以看到你的显卡信息,比如我的就是

product: GM107M [GeForce GTX 960M] [10DE:139B]

找到 系统设置->软件更新->附加驱动

查看和上面GPU型号相对应的显卡

选择最新的显卡驱动并点击应用更改

然后喝杯咖啡静候应用更改完成

输入以下命令:

1
sudo apt-get install mesa-common-devsudo apt-get install freeglut3-dev

安装完成之后,重启电脑,驱动应该就完成了!

你可以在dashboard上搜索nvidia

看到像 NVIDIA X Server Settings的东西

就说明安装驱动成功了

接下来就该安装cuda8

安装cuda8

首先也是去下载cuda toolkit 8.0

老铁!看我的教程就按我的来!照着图好好选!

一定要选择runfile.下载完成之后,执行

1
sudo sh cuda_8.0.44_linux.run

然后就进入安装过程

开始都是End User License Agreement

你可以CTRL +C 跳过

然后accept,下面就是安装的交互界面

开始的Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 375.66?

选择n,因为你已经安装驱动了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Using more to view the EULA.
End User License Agreement
Preface
The following contains specific license terms and conditionsfor four separate NVIDIA products. By accepting this
agreement, you agree to comply with all the terms andconditions applicable to the specific product(s) included
herein.
NVIDIA CUDA Toolkit
Description
The NVIDIA CUDA Toolkit provides command-line and graphical
tools for building, debugging and optimizing the performanceof applications accelerated by NVIDIA GPUs, runtime and math
libraries, and documentation including programming guides,
user manuals, and API references. The NVIDIA CUDA Toolkit
License Agreement is available in Chapter 1.Default Install Location of CUDA Toolkit
Windows platform:
Do you accept the previously read EULA?
accept/decline/quit: accept
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 367.48?
(y)es/(n)o/(q)uit: n
Install the CUDA 8.0 Toolkit?
(y)es/(n)o/(q)uit: y
Enter Toolkit Location
[ default is /usr/local/cuda-8.0 ]:
Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y
Install the CUDA 8.0 Samples?
(y)es/(n)o/(q)uit: y
Enter CUDA Samples Location
[ default is /home/kinny ]:
Installing the CUDA Toolkit in /usr/local/cuda-8.0 ...
Missing recommended library: libXmu.so
Installing the CUDA Samples in /home/kinny ...
Copying samples to /home/kinny/NVIDIA_CUDA-8.0_Samples now...
Finished copying samples.
===========
= Summary =
===========
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-8.0Samples: Installed in /home/kinny, but missing recommended libraries
Please make sure that
- PATH includes /usr/local/cuda-8.0/bin
- LD_LIBRARY_PATH includes /usr/local/cuda-8.0/lib64, or, add /usr/local/cuda-8.0/lib64 to /etc/ld.so.conf and run ldconfig as root
To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-8.0/bin
Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-8.0/doc/pdf for detailed information on setting up CUDA.
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 361.00 is required for CUDA 8.0 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
sudo <CudaInstaller>.run -silent -driver
Logfile is /tmp/cuda_install_17494.log

配置cuda环境变量

1
export PATH="$PATH:/usr/local/cuda-8.0/bin"export LD_LIBRARY_PATH="/usr/local/cuda-8.0/lib64"nvidia-smi

结果出现以下输出,说明配置成功

安装深度学习库cuDNN-v5.1

首先下载cuDNN5.1,直接下载,注意前提是你已经注册为开发者了!

解压:

1
tar xvzf cudnn-8.0-linux-x64-v5.1.tgz

然后将库头文件Copy到cuda目录

1
2
3
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

安装tensorflow gpu enable python 2.7 版本,详见官网

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whlsudo pip install --upgrade $TF_BINARY_URL
验证
$python
Python 2.7.12 (default, Jul 1 2016, 15:12:24)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcurand.so locally
>>> quit()
大功告成!

全部结束 谢谢观看!

现在就可以放心的开始你的深度学习之路了

不要觉得好容易。。。都是几十遍血的教训成就的!

之后我会继续更新个人公众号,发布一些自己在深度学习方面的见闻。


CreatedbyEdwardZhang∣一个不只做技术的公众号





长按,识别二维码,加关注


0.gif
0.gif